var groupEdit = {
	groupId:null
};

$(function(){
	changeActiveItem('groupList');
	initData();
	setData();
});

function successCallBack(){
	window.location.href = 'groupList.jsp';
}
/**
 * 提示信息处理
 */
function savehandle(){
	$('#alertdiv').hide();
	$('#alertdiv').savehandle({
		fieldMap:{},
		successMsg:"提交成功！",
		failMsg:"提交失败，请重试！",
		success:successCallBack
	});
}

function initData() {
	var id =location.hash;
	var ids = id.substring(1, id.length).split(',');
	groupEdit.groupId = ids[0];
	savehandle();
}

/**
* 获取信息
*/
function setData(){
	$.getJSON(
		'/fw/auth/group_getGroupById.action',
		{
			groupId: groupEdit.groupId
		},
		function(data){
			if(data.rows && data.total){
				var rows = data.rows[0];
				if(rows.groupName) {
					$('#groupEdit #groupName').val(rows.groupName);
				}
				if(rows.remarks) {
					$('#groupEdit #remarks').val(rows.remarks);
				}
				if(rows.loginUrl){
					$('#groupEdit #loginUrl').val(rows.loginUrl);
				}
			}
		}
	);
}

/**
 * 提交信息
 * @return {TypeName} 
 */
function edit() {
	var groupName = $('#groupName').val(),
		remarks = $('#remarks').val(),
		loginUrl=$('#loginUrl').val()
	if(!$('#groupEdit #groupEditForm').validate()){
		return false;
	}else{
		$('#groupEdit #groupEditForm .alert-danger').hide();
	}
	$.getJSON(
		'/fw/auth/group_edit.action',
		{
			groupId: groupEdit.groupId,
			groupName: groupName,
			remarks: remarks,
			"loginUrl":loginUrl
		},
		function(data){
			$('#alertdiv').savehandle('handle',data,2000);
		}
	);
}

/**
 * 重置表单信息
 */
function resetGroup(){
	setData();
}

